We consider nilpotent Lie groups for which the derived subgroup is abelian. We equip them with sub-Riemannian metrics and we study the normal Hamiltonian flow on the cotangent bundle. We show a correspondence between normal trajectories and polynomial Hamiltonians in some Euclidean space. We use the aforementioned correspondence to give a criterion for the integrability of the normal Hamiltonian flow. As an immediate consequence, we show that in Engel-type groups the flow of the normal Hamiltonian is integrable. For Carnot groups that are semidirect products of two abelian groups, we give a set of conditions that normal trajectories must fulfill to be globally length-minimizing. Our results are based on a symplectic reduction procedure.